package com.atguigu.c_threadstart2;

public class Demo {
    public static void main(String[] args) {
        //创建线程的任务对象
        MyTarget target = new MyTarget();

        //创建线程对象并接受任务对象
        //Thread(Runnable target, String name)
        Thread t1 = new Thread(target,"线程1 : ");

        //t1.setName("线程1 : ");


        //匿名内部类的方式实现新线程的开启
        //匿名内部类的方式更推荐
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <= 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "Python" + i);
                }
            }
        },"线程2 : ");

        //启动线程
        t1.start();
        t2.start();


        //修改main线程的名称
        Thread.currentThread().setName("主线程");
        //在main线程中编写代码
        for (int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + " : Java" + i);
        }
    }
}
